package com.atguigu.jucdemo.lock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class DeadLockDemo1 {
    private Object o1 = new Object();
    private Object o2 = new Object();
    public void t1(){
        synchronized (o1){
            System.out.println(Thread.currentThread().getName()+"进入线程尝试获取o2锁");
            synchronized (o2){

            }
        }
    }
    public void t2(){
        synchronized (o2){
            System.out.println(Thread.currentThread().getName()+"进入线程尝试获取o1锁");
            synchronized (o1){

            }
        }
    }

    public static void main(String[] args) {
        DeadLockDemo deadLockDemo = new DeadLockDemo();
        new Thread(()->{deadLockDemo.t1();},"A").start();
        new Thread(()->{deadLockDemo.t2();},"B").start();
    }
}
